<?php
/**
 *
 */
class User_model extends CI_Model{

    public function __construct(){
        parent::__construct();
    }

    public function check_account($account){
        if(empty($account)) return false;

        $sql = "SELECT * FROM " . INET_USERS . " WHERE `account` = '{$account}'";
        $result = $this->db->query($sql);
        if($result -> result() && $result->result_id){
            return true;
        }

        return false;
    }

    public function check_login($account,$password){
        if(empty($account) || empty($password)) return false;

        $sql = "SELECT * FROM " . INET_USERS . " WHERE `account` = '{$account}' AND `password` = '{$password}' LIMIT 1";
        $result = $this->db->query($sql) -> result('array');

        if(count($result) > 0){
            return true;
        }
        return false;
    }

    public function edit_password($pw) {
        try{
            $sql = "UPDATE " . INET_USERS . " SET `password` = md5('%s') WHERE `account` = '%s'";
            $sql = sprintf($sql, $pw, $_SESSION['inet_account']);
            $result = $this -> db -> simple_query($sql);
            if($result) {
                return true;
            } else {
                return false;
            }
        } catch (Exception $e) {
            return false;
        }
    }
}
?>